<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <school></school>
        <hr>
        <student></student>
        <hr>
        <hello></hello>
    </div>

    <div id="app2">
        <hello></hello>
    </div>

    <script src="/Vue/Vue基础/JS/vue.js"></script>
    <script>

        //第一步：创建school组件
        const school = Vue.extend({
            //el: '#app', //组件定义时一定不要写el配置项，因为最终虽有的组件都要被一个vm管理，由vm决定服务哪个容器
            data() {
                return {
                    schoolName: '家里蹲大学',
                    address: '家里',
                }
            },
            template: `
                <div>
                    <h2>学校名称：{{ schoolName }}</h2>
                    <h2>学校地址：{{ address }}</h2>
                    <button @click="fn">点我提示学校名称</button>
                </div>
            `,
            methods: {
              fn(){
                alert(this.schoolName)
              }  
            },
        })

        //第一步：创建student组件
        const student = Vue.extend({
            data() {
                return {
                    studentName: '张三',
                    age: 18,
                }
            },
            template:`
                <div>
                    <h2>学生姓名：{{ studentName }}</h2>
                    <h2>学生年龄：{{ age }}</h2>
                </div>
            `
        })

        //创建全局组件
        const hello = Vue.extend({
            template:`
                <h2>Hello 我是全局组件</h2>
            `,
        })

        //注册全局组件
        Vue.component('hello',hello)
        new Vue({
            el: '#app',
            //第二步注册组件(局部注册)
            components: {
                school: school,
                student,
            }
        })

        new Vue({
            el:'#app2',
        })
    </script>
</body>

</html>